home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
oocs
/
cclienta.cls
next >
Wrap
Text File
|
1999-09-06
|
9KB
|
304 lines
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "cClientActions"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
'***********************************************************************
'***********************************************************************
'** **
'** cClientActions.cls - This class handles most of the winsock **
'** Functions.
'** **
'** **
'***********************************************************************
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'^^ Author: gh0ul -@- August 99' ^^
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'***********************************************************************
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^'
' '
' C L A S S - P R O P E R T I E S '
' '
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^'
Public SystemDir As String
Public WindowsDirectory As String
Public MemLoad As String
Public TotalPhys As String
Public AvailPhys As String
Public TotalPFile As String
Public AvailPFile As String
Public TotalVir As String
Public AvailVir As String
Private m_sIPAddress As String
Private ChnkCnt As Integer ' Data Chunk Counter.
Private m_FilePath As String
Private m_NumFiles As Long
Public Packaged_SysInfo As String
Public CurDrive As String
Public IPAddress As String
' event to signify a connection has been made so that
' the client knows when to unload the IP Form.
Public Event ConnMade()
' this event lets the form know that a new chunk of data
' has been recieved and needs to be dealt with.
Public Event IncomingDataChunk()
' this event lets the form know when all the data chunks
' have been sent
Public Event TransferDone()
Public Event DriveInputError()
Public Event SysInfoArrival()
Public Property Get FilePath() As String
'
FilePath = m_FilePath
End Property
Public Property Let FilePath(ByVal sNV As String)
m_FilePath = FilePath
End Property
Public Property Get NumFiles() As Long
NumFiles = m_NumFiles
End Property
Public Property Let NumFiles(ByVal lNV As Long)
m_NumFiles = lNV
End Property
Private Sub Class_Initialize()
WindowsDirectory = "WIndows Directory"
MemLoad = "Memory Load:"
TotalPhys = "Total Physical Memory:"
AvailPhys = "Available Physical Memory:"
TotalPFile = "Pagefile Size:"
AvailPFile = "Available Pagefile Resources:"
TotalVir = "Total Virtual Memory:"
AvailVir = "Available Virtual Memory:"
End Sub
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^'
' '
' C L A S S - M E T H O D S '
' '
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^'
Sub Connect(sIPAddress As String, Client As Winsock)
'
If sIPAddress = "" Then Exit Sub
m_sIPAddress = sIPAddress
' for public access
IPAddress = m_sIPAddress
'try to make a connection to the Server.
bReplied = False
Client.Connect sIPAddress, 333
lTIme = 0
While (Not bReplied) And (lTIme < 10000)
DoEvents
lTIme = lTIme + 1
Wend
If lTIme >= 10000 Then
'Didn't reply or timed out. close the connection
MsgBox "Unable to connect to remote server", vbCritical, "Connection Error"
Client.Close
Exit Sub
End If
' connection made!
RaiseEvent ConnMade
End Sub
Sub DisConnect(Client As Winsock)
'
Client.Close
End Sub
Sub HandleIncomingData(sIncoming As String, Client As Winsock, Div As String)
'
Dim Command As String
Dim sIncomingData As String
'--- when a command is sent the first seperater is a comma, the default.
'--- Therefore "sDivider" is not set.
' Extract the command from the Left
' of the comma (default divider)
Command = EvalData(sIncoming, 1, Div)
' extract the data being sent from the
' right of the comma (default divider)
sIncomingData = EvalData(sIncoming, 2, Div)
' decide what command has been issued
Select Case Command
Case "Accepted"
bReplied = True
Case "NumFiles"
m_NumFiles = CLng(sIncomingData)
Case "Users_Data"
' assign the new chunk to the FilePath property
' to expose it
m_FilePath = sIncomingData
' notify the form that a new chunk has been set
RaiseEvent IncomingDataChunk
Case "SysInfo"
' assign the sent data to a public
' property, so it will be exposed to the forms
' and modules
Packaged_SysInfo = sIncomingData
' trigger an event to do something
' with newly recieved System Info
RaiseEvent SysInfoArrival
Case "Transfer_Done"
RaiseEvent TransferDone
End Select
End Sub
'======================================================================
' (EvalData Function)
'
' Purpose - Extract data from a given string, to the right or left
' of a specified character.
'
' Parameters:
' sIncoming - The String you want to extract data from.
' iRtLt - Extract from the Left, 1.
' Extract from the right, 2.
' sDivider - The character that seperates the data in
' the string. <default = ",">
' Returns:
' the data to the right or left of strDivider
'======================================================================
Function EvalData(sIncoming As String, iRtLt As Integer, _
Optional sDivider As String) As String
Dim i As Integer
Dim TempStr As String
' Storage for the current Divider
Dim sSplit As String
' the current character used to divide the data
If sDivider = "" Then
sSplit = ","
Else
sSplit = sDivider
End If
' getting the right or left?
Select Case iRtLt
Case 1
' remove the data to the Left of the Current Divider
For i = 0 To Len(sIncoming)
TempStr = Left(sIncoming, i)
If Right(TempStr, 1) = sSplit Then
EvalData = Left(TempStr, Len(TempStr) - 1)
Exit Function
End If
Next
Case 2
' remove the data to the Right of the Current Divider
For i = 0 To Len(sIncoming)
TempStr = Right(sIncoming, i)
If Left(TempStr, 1) = sSplit Then
EvalData = Right(TempStr, Len(TempStr) - 1)
Exit Function
End If
Next
End Select
End Function
' --- Prompts the User for a string, sends it to the server,
' --- if not already being used
Sub SendMsg(Client As Winsock)
Dim sMsg As String
sMsg = InputBox("Enter a string to send")
On Error GoTo ErrH
If sMsg = "" Then
Exit Sub
End If
If (Not SendData("Msg," & sMsg)) Then
Client.Close
End I